package common.controls.utils
{
	import mx.utils.StringUtil;

	public class DateUtils
	{

		public static function getFullTimeStr():String
		{
			var date:Date =new Date();
			var str:String=date.fullYear + "_" + (date.month + 1) + "_" + date.date + "_" + date.hours + "_" + date.minutes + "_" + date.seconds;
			return str;
		}

		public static function formatFromSecond(second:uint):String
		{

			var date:Date =new Date(second * 1000);
			var str:String=StringUtil.substitute("{0}年{1}月{2}日{3}时{4}分", date.fullYear, date.month + 1, date.date, date.hours, date.minutes);
			return str;
		}

		public static function formatFromlSecond(second:uint):String
		{
			var date:Date =new Date(second * 1000);
//			var str:String=date.fullYear+"年"+date.month+"月"+date.date+"日"+date.hours+":"+date.minutes;
			var str:String=date.month + "月" + date.date + "日" + date.hours + ":" + date.minutes;

			return str;
		}

		public static function formatFromSecond1(second:uint):String
		{

			var date:Date =new Date(second * 1000);
			var str:String=StringUtil.substitute("{0}年{1}月{2}日", date.fullYear, date.month, date.day);
			return str;
		}

		public static function getLocalDateOfUTC(date:Date = null):Date
		{
			if (date == null)
				date=new Date();
			date.setTime(date.time - (date.getTimezoneOffset() * 60 * 1000));
			return date;
		}

		public static function getTimehhmmss(date:Date = null, utc:Boolean = true):String
		{
			if (date == null)
				date=new Date();
			return getFormatNum(utc ? date.hoursUTC : date.hours) + ':' + getFormatNum(utc ? date.minutesUTC : date.minutes) + ':' + getFormatNum(utc ? date.secondsUTC : date.seconds);
		}

		public static function getTimeFormatFromSeconds(second:uint):String
		{
			var h:int=second / 3600;
			var m:int=int(second % 3600) / 60;
			var s:int=int(second % 60);
			return getFormatNum(h) + ":" + getFormatNum(m) + ":" + getFormatNum(s);
		}

		public static function getTimeFormatFromSeconds2(second:uint):String
		{
			var h:int     =second / 3600;
			var m:int     =int(second % 3600) / 60;
			var ret:String="";
			if (h > 0)
			{
				ret+=(getFormatNum(h) + "小时");
			}
			if (m > 0)
			{
				ret+=(getFormatNum(m) + "分钟");
			}
			return ret;
		}

		public static function getTimeFormatFromSeconds3(second:uint):String
		{
			var h:int=second / 3600;
			var m:int=int(second % 3600) / 60;
			var s:int=second % 60;
			return getFormatNum(h) + "小时" + getFormatNum(m) + "分钟" + getFormatNum(s) + "秒";
		}

		public static function getTimeFormatFromSeconds7(second:uint):String
		{
			var m:int=int(second / 60);
			var s:int=second % 60;
			return getFormatNum(m) + "分钟" + getFormatNum(s) + "秒";
		}

		public static function getTimeFormatFromSeconds4(second:uint):String
		{
			var h:int     =second / 3600;
			var m:int     =int(h / 24);
			var ret:String="";
			if (m > 1)
			{
				ret=m + "天";
			}
			else
			{
				ret="1天";
			}
			return ret;
		}

		public static function getTimeFormatFromSeconds44(second:uint):String
		{
			var h:int     =second / 3600;
			var m:int     =int(h / 24);
			var ret:String="";
			if (m > 1)
			{
				ret=m + "";
			}
			else
			{
				ret="1";
			}
			return ret;
		}

		public static function getTimeFormatFromSeconds5(second:uint):String
		{
			var m:uint=second / 60;
			var s:uint=second % 60;
			return m + ":" + s;
		}

		public static function getTimeFormatFromSeconds6(second:uint):String
		{
			var h:int     =second / 3600;
			var m:int     =int(second % 3600) / 60;
			var ret:String="";
			if (h > 0)
			{
				ret=(h + "小时");
			}
			else if (m > 0)
			{
				ret=(m + "分钟");
			}
			return ret;
		}

		public static function getTimeFormatFromSeconds8(second:uint):String
		{
			var date:Date =new Date(second * 1000);
			var str:String=date.month + "月" + date.date + "日   " + date.hours + ":" + date.minutes;
			return str;
		}

		public static function getFormatNum(value:int):String
		{
			if (value < 10)
			{
				return "0" + value;
			}
			return value.toString();
		}

		public function DateUtils()
		{
		}
	}
}
